import React, { Component, Suspense } from 'react'
// imrr导入快捷键
import { Router, Route, Switch, Redirect } from 'react-router-dom'
import AuthRoute from 'components/AuthRoute'
import { history } from 'utils/history'
const Login = React.lazy(() => import('pages/Login'))
const Layout = React.lazy(() => import('pages/Layout'))

class App extends Component {
  render() {
    return (
      <Router history={history}>
        <Suspense fallback={<div>loding...</div>}>
          <Switch>
            <Redirect exact from="/" to="/home"></Redirect>
            {/* 需要在路由里判断是否有 token */}
            {/* 需要用路由的 render 写法,但是因为是用render 所以需要手动传 props */}
            {/* <Route
            path="/login"
            render={(props) => {
              return <Login {...props} />
            }}
          ></Route> */}
            {/* <AuthRoute path="/login" component={Login}></AuthRoute> */}
            <Route path="/login" component={Login}></Route>
            {/* <Route
            path="/login"
            render={(props) => {
              if (hasToken()) {
                return <Login />
              } else {
                return <Redirect to="/login"></Redirect>
              }
            }}
          ></Route> */}
            <AuthRoute path="/home" component={Layout}></AuthRoute>
          </Switch>
        </Suspense>
      </Router>
    )
  }
}

export default App
